package base_NIO.FileChannel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class m {
    public static void main(String[] args) {
        FileChannel inChannel=null;
        FileChannel outChannel=null;
        FileInputStream fileInputStream=null;
        FileOutputStream fileOutputStream=null;

        try{
            fileInputStream = new FileInputStream("a.jpg");
            fileOutputStream=new FileOutputStream("b.jpg");
            inChannel=fileInputStream.getChannel();
            outChannel=fileOutputStream.getChannel();
            ByteBuffer byteBuffer=ByteBuffer.allocate(1024);
            while (inChannel.read(byteBuffer)!=-1){
                byteBuffer.flip();
                outChannel.write(byteBuffer);
                byteBuffer.clear();
            }
        }catch (Exception e){
            System.out.println(e.toString());
        }
    }
}
